﻿using EvertonApp.Data.UnitOfWork;
using EvertonApp.Transporte;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace EvertonApp.WebAPI.Controllers
{
    public class ComercioController : ApiController
    {
        private ComerciosUoW _comercios;
        public ComercioController() {
            _comercios = new ComerciosUoW();
        }

        // GET api/comercio
        public IEnumerable<Comercio> Get()
        {
            IQueryable<Comercio> comercios = _comercios.ComerciosRepository.GetAll();

            return comercios.AsEnumerable();
        }

        // GET api/comercio/id
        public Comercio Get(Guid id)
        {
            return _comercios.ComerciosRepository.GetById(id);
        }

        // POST api/comercio
        public Comercio Post([FromBody]Comercio value)
        {
           return _comercios.ComerciosRepository.Insert(value);
        }

        // PUT api/comercio/5
        public bool Put(Guid id, [FromBody]Comercio value)
        {
            return _comercios.ComerciosRepository.Update(id, value);
        }

        // DELETE api/comercio/5
        public bool Delete(Guid id)
        {
           return _comercios.ComerciosRepository.Delete(_comercios.ComerciosRepository.GetById(id)); 
        }
    }
}
